package com.zhuxulin.tab.listeners;

import java.util.ArrayList;

import com.zhuxulin.midi.event.MidiEvent;
import com.zhuxulin.midi.util.MidiEventListener;
import com.zhuxulin.midi.util.MidiProcessor;
import com.zhuxulin.tab.App;
import com.zhuxulin.tab.bluetooth.ISendMsg;
import com.zhuxulin.tab.utils.LogUtils;

public class MidiListener implements MidiEventListener {
	private static final String TAG = MidiListener.class.getSimpleName();
	private App app = null;
	private ISendMsg sendMsg = null;
	private MidiProcessor processor = null;

	public MidiListener(App app) {
		this.app = app;
		processor = app.getProcessor();
	}

	@Override
	public void onStop(boolean finished) {
		LogUtils.i(TAG, "onStop!Finished:" + finished);
	}

	@Override
	public void onStart(boolean fromBeginning) {
		LogUtils.i(TAG, "onStart!FromeBeginning:" + fromBeginning);
	}

	@Override
	public void onEvent(MidiEvent event, long ms) {
		if (event == null) {
			LogUtils.i(TAG, "event is null!");
			// processor.stop();
			return;
		}
		if (event.getCmd() == null) {
			LogUtils.i(TAG, "cmd is null!");
			// processor.stop();
			return;
		}
		if ((sendMsg = app.getSendMsg()) == null) {
			LogUtils.i(TAG, "SendMsg is null,plese connect it!");
			processor.stop();
			return;
		}
		LogUtils.i(TAG, "BeginSendCmd");
		sendMsg.sendMessage(event.getCmd());
		LogUtils.i(TAG, "EndSendCmd");
	}

	@Override
	public void onEvents(ArrayList<MidiEvent> events, long mMsElapsed) {
		// TODO Auto-generated method stub
		
	}

}
